package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    // 查询
    List<User> selectList(UserDto userDto);
    // 添加用户
    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time)values (#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void insert(User user);

    //@Delete("delete from user where id in (${ids})")
    void deleteUsersById(List<Integer> ids);


    @Select("select * from user where id = #{id}")
    User getById(Integer id);

    // 修改用户
    void updateUsers(User user);

    // 查询所有用户
//    @Select("select * from user")
    @Select("select u.*,d.name dept_name,r.name role_name,r.label role_label from user u left join dept d on u.dept_id =d.id left join role r  on u.role_id = r.id")
    List<User> list();

    // 根据角色查询用户
//    @Select("select * from user where status = 1 and role_id in (select id from role where label=#{roleLabel})")
    @Select("select u.*,d.name dept_name,r.name role_name,r.label role_label from user u left join dept d on u.dept_id =d.id left join role r on u.role_id = r.id where u.status = 1 and r.label = #{roleLabel}")
    List<User> listByRole(String roleLabel);



    @Select("select * from user where status = 1 and dept_id = #{deptId}")
    List<User> listByDept(Integer deptId);


    //登录 根据用户名查询信息
    @Select("select u.*,r.label role_label from user u left join role r on u.role_id = r.id where username=#{username}")
    User getByUsername(String username);
}
